class_name DamageEffect
extends Effect

var amount := 0
var receiver_modifier_type := Modifier.Type.DMG_TAKEN

func execute(targets: Array[Node]) -> void:
	for target in targets:
		if not target:
			continue
		if target is Enemy or target is Player:
			# 获取攻击者的modifier_handler（通常是玩家）
			var attacker_modifier_handler = _get_attacker_modifier_handler(targets)
			
			# 使用攻击者的修改器来增强伤害
			var final_amount = get_enhanced_amount(amount, attacker_modifier_handler)
			
			target.take_damage(final_amount, receiver_modifier_type)
			
			# 如果数值被增强，显示提示
			if final_amount > amount:
				print("🚀 伤害效果翻倍激活！基础: %d → 最终: %d" % [amount, final_amount])
			
			SFXPlayer.play(sound)

# 获取攻击者的modifier_handler
func _get_attacker_modifier_handler(targets: Array[Node]) -> ModifierHandler:
	# 尝试从场景树中获取玩家
	var tree = null
	if targets and targets.size() > 0:
		tree = targets[0].get_tree()
	
	if tree:
		var player = tree.get_first_node_in_group("player")
		if player and player.get("modifier_handler") != null:
			return player.modifier_handler
	
	# 如果无法获取，返回null
	return null
